import { defineStore } from 'pinia'

import ajax from '../axios/axjos.js'

export const useEmpStore = defineStore('emp', {
  state: () => ({
    emps: [],
    emp: {
      empno: 7369,
      logpwd: '123456'
    }
  }),
  actions: {
    async login() {
      // ajax 请求三剑客
      const path = `/emp/login/${this.emp.empno}/${this.emp.logpwd}`
      const { data: res } = await ajax.get(path)

      if (res && res.code === 200) {
        const emp = res.result
        console.log(emp)
        sessionStorage.setItem('emp', JSON.stringify(emp))
        sessionStorage.setItem('token', emp.token)
      }
    }
  }
})
